//
//  TopTimeCell.m
//  Estate
//
//  Created by heyong on 16/7/10.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "TopTimeCell.h"
#import "ActionSheetDatePicker.h"

@implementation TopTimeCell

- (UIImageView *)imageView1{
    if(_imageView1==nil){
        _imageView1=[[UIImageView alloc]init];
    }
    return _imageView1;
}

- (UIImageView *)imageView2{
    if(_imageView2==nil){
        _imageView2=[[UIImageView alloc]init];
    }
    return _imageView2;
}

- (void)setIsEdit:(BOOL)isEdit{
    if(isEdit){
        self.imageView2.userInteractionEnabled=YES;
    }else{
        self.imageView2.userInteractionEnabled=NO;
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self createView];
    }
    return self;
}

- (void)createView{
    //创建背景视图
    UIView *view1=[[UIView alloc]initWithFrame:CGRECTS(0, 2, 187.5, 100)];
    view1.backgroundColor=[UIColor colorWithRed:0.49 green:0.78 blue:0.76 alpha:1.00];
    [self.contentView addSubview:view1];
    UIView *view2=[[UIView alloc]initWithFrame:CGRECTS(187.5, 2, 187, 100)];
    view2.backgroundColor=[UIColor colorWithRed:0.84 green:0.63 blue:0.53 alpha:1.00];
    [self.contentView addSubview:view2];
    //文字
    UILabel *label1=[[UILabel alloc]initWithFrame:CGRECTS(172.5, 35, 30, 30)];
    label1.backgroundColor=[UIColor whiteColor];
    label1.text=@"至";
    label1.textColor=[UIColor colorWithRed:0.67 green:0.32 blue:0.18 alpha:1.00];
    label1.font=[UIFont systemFontOfSize:14.];
    label1.layer.cornerRadius=15.f;
    label1.textAlignment=1;
    label1.layer.masksToBounds=YES;
    [self.contentView addSubview:label1];
    
    //修改按钮
    self.imageView1.image=[UIImage imageNamed:@"xiugai_btn"];
    self.imageView1.tag=100;
    [view1 addSubview:self.imageView1];
    [self.imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(2);
        make.bottom.mas_offset(-2);
        make.left.offset(0);
        make.width.offset(65*BIZ);
    }];
    
    //生成按钮
    self.imageView2.image=[UIImage imageNamed:@"shengcheng_btn"];
    self.imageView2.tag=101;
    [view2 addSubview:self.imageView2];
    [self.imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(2);
        make.bottom.mas_offset(-2);
        make.right.offset(0);
        make.width.offset(65*BIZ);
    }];
    
    //label
    UILabel *begin=[[UILabel alloc]init];
    begin.text=@"旁站监理开始时间";
    begin.font=[UIFont systemFontOfSize:12.];
    begin.textColor=[UIColor colorWithRed:0.73 green:0.91 blue:0.89 alpha:1.00];
    [view1 addSubview:begin];
    [begin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20*BIZ);
        make.height.offset(10*BIZ);
        make.left.mas_equalTo(self.imageView1.mas_right).mas_offset(5);
    }];
    
    //label
    UILabel *end=[[UILabel alloc]init];
    end.text=@"旁站监理结束时间";
    end.font=[UIFont systemFontOfSize:12.];
    end.textColor=[UIColor colorWithRed:0.53 green:0.36 blue:0.27 alpha:1.00];
    [view2 addSubview:end];
    [end mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20*BIZ);
        make.height.offset(10*BIZ);
        make.right.mas_equalTo(self.imageView2.mas_left).mas_offset(-5);
    }];
    
    //添加点击事件
//    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(scTime:)];
    UITapGestureRecognizer *tap2=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(scTime:)];
//    [self.imageView1 addGestureRecognizer:tap1];
    [self.imageView2 addGestureRecognizer:tap2];
    
    //设置开始时间
    _beginLab=[[UILabel alloc]init];
    _beginLab.font=[UIFont systemFontOfSize:13];
    _beginLab.numberOfLines=0;
    
    _beginLab.textColor=[UIColor colorWithRed:0.93 green:1.00 blue:1.00 alpha:1.00];
    [view1 addSubview:_beginLab];
    [_beginLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(begin.mas_left);
        make.top.mas_equalTo(begin.mas_bottom).offset(0);
        make.width.offset(80);
        make.height.offset(60*BIZ);
    }];
    
    //设置结束时间
    _endLab=[[UILabel alloc]init];
    _endLab.font=[UIFont systemFontOfSize:13];
    _endLab.numberOfLines=0;
    _endLab.textColor=[UIColor colorWithRed:0.93 green:1.00 blue:1.00 alpha:1.00];
    
    [view2 addSubview:_endLab];
    [_endLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(80);
        make.top.mas_equalTo(begin.mas_bottom).offset(0);
        make.right.mas_equalTo(end.mas_right);
        make.height.offset(60*BIZ);
    }];
 
}

#pragma  mark-methld

- (void)scTime:(UITapGestureRecognizer *)tap {
    WEAKSELF
    UIImageView *image=(UIImageView *)tap.view;
    
    if(self.clickTimeBlock){
        if(image.tag==100){
            _beginLab.text = [LSUtility TimeNow];
            self.clickTimeBlock(_beginLab.text);
        }
    }
    if(self.clickTimeBlock_end) {
        
        if(image.tag==101) {
            
            NSDate *curDate = [NSDate date];
            
            ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc] initWithTitle:nil datePickerMode:UIDatePickerModeDateAndTime selectedDate:curDate doneBlock:^(ActionSheetDatePicker *picker, NSDate *selectedDate, id origin) {
                
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSString *strDate = [dateFormatter stringFromDate:selectedDate];
                _endLab.text = strDate;
                weakSelf.clickTimeBlock_end(strDate);
                
            } cancelBlock:^(ActionSheetDatePicker *picker) {
                NSLog(@"%@", picker.description);
                
            } origin:weakSelf.contentView];
            
            picker.minimumDate = [NSDate date];
            [picker showActionSheetPicker];
            
//            _endLab.text=[LSUtility TimeNow];
//            self.clickTimeBlock_end(_endLab.text);
        }
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
